<?php

class ipadProductPageActions extends myFrontendAction{


	public function preExecute(){
		$this->setLayout(false);

		$this->helper = new iPadProductPageHelper();
	}

	
	public function executeIndex(sfWebRequest $request){

		if(!$this->getRoute()->getProductObject()){
			return sfView::NONE;
		}


		$this->product = $this->getRoute()->getProductObject();
		$this->productMainPicture = $this->getProductMainPicture();
		$this->productPalettes = $this->getProductPalettes();
		$this->productGroup = $this->getProductGroup();

		$this->defaultParameters = $this->getProductDefaultParameters();


		$this->params = $this->getVarHolder()->getAll();


	}

	
	public function executeScannedPage(sfWebRequest $request){
		$this->setLayout('layout_index');
		
		$this->product = $this->getRoute()->getProductObject();
		$this->productMainPicture = $this->getProductMainPicture();
		$this->productPalettes = $this->getProductPalettes();
		$this->productGroup = $this->getProductGroup();

		$this->defaultParameters = $this->getProductDefaultParameters();


		$this->params = $this->getVarHolder()->getAll();
	}

	
	protected function getProductMainPicture(){
		return Doctrine::getTable('ProductPictures')->createQuery()
				->select('p.file as file, p.id as id')
				->from('ProductPictures p')
				->where('p.parameter = ? and p.product_id = ?', array('default',$this->getRoute()->getProductObject()->getId()) )
				->orderBy('p.pri desc')
				->setHydrationMode(Doctrine::HYDRATE_ARRAY)
				->fetchOne();
	}

	protected function getProductPalettes(){
		return Doctrine::getTable('ProductPictures')->createQuery()
				->select('p.id, p.file')
				->from('ProductPictures p')
				->where('p.parameter = ? and p.product_id = ?', array('all palettes',$this->getRoute()->getProductObject()->getId()) )
				->orderBy('p.pri desc')
				->setHydrationMode(Doctrine::HYDRATE_ARRAY)
				->fetchOne();
	}

	protected function getProductGroup(){
		if($this->getRoute()->getProductObject()->getProductGroups()){
			return $this->getRoute()->getProductObject()->getProductGroups()->getFirst()->getProductGroup();
		}

		return false;
	}

	protected function getProductDefaultParameters(){
		return $this->helper->getProductParameters($this->getRoute()->getProductObject());
	}

	protected function getProductRank(){
		
	}


	protected function getProductKeyIngredients(){
		
	}


	protected function getProductIngredients(){
		
	}

}